class MyPromise {

  static all(promises) {
    return new MyPromise((resolve, reject) => {
      if (!Array.isArray(promises)) {
        return reject(new TypeError('arguments must be array'))
      }
      let count = 0
      let promiseCount = promises.length
      let results = new Array(promiseCount)
      for (let i = 0; i < promiseCount; i++) {
        MyPromise.resolve(promises[i]).then((value) => {
          count++
          results[i] = value
          if (count === promiseCount) {
            resolve(results)
          }
        }, (error) => {
          return reject(error)
        })
      }
    })
  }
}
